package com.shr.lease.common.exception;

import com.shr.lease.common.result.ResultCodeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Haoran Sun
 * @since 2024/06/18
 */

@Data
@NoArgsConstructor
//  继承运行时异常，直接抛出不同在父类做throw处理，
//  异常传递到controller层时直接被全局异常处理捕获，
public class LeaseException extends RuntimeException{

    private Integer code;

    public LeaseException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public LeaseException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "LeaseException{" +
                "code=" + code +
                ", message='" + this.getMessage() + '\'' +
                '}';
    }
}
